//
//  YSPhotoBroser.m
//  A_target
//
//  Created by sss on 2018/6/12.
//  Copyright © 2018年 kb210. All rights reserved.
//

#import "YSPhotoBroser.h"
#import "YSPhotoCell.h"
@implementation YSPhotoBroser

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
#define kWidth 414
-(instancetype)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    if (self) {
        [self addSubview:self.collectionView];
    }
    return self;
}
-(UICollectionView *)collectionView{
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
        layout.itemSize=CGSizeMake(kWidth, 667);
        layout.minimumLineSpacing=0;
        layout.minimumInteritemSpacing=0;
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _collectionView=[[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:layout];
        [_collectionView registerNib:[UINib nibWithNibName:@"YSPhotoCell" bundle:nil] forCellWithReuseIdentifier:@"photo"];
        _collectionView.pagingEnabled=YES;
        _collectionView.showsVerticalScrollIndicator=NO;
        _collectionView.showsHorizontalScrollIndicator=NO;
        _collectionView.delegate=self;
        _collectionView.dataSource=self;
        _collectionView.backgroundColor=[UIColor whiteColor];
    }
    return _collectionView;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 5;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    YSPhotoCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"photo" forIndexPath:indexPath];
    NSArray *arr=@[@"笔记漂流bg1",@"welch"];
    cell.img=[UIImage imageNamed:arr[indexPath.item%2]];
    
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"0000");
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    CGFloat offsetx= scrollView.contentOffset.x;
    NSInteger index = offsetx/kWidth;
    [scrollView setContentOffset:CGPointMake(index*kWidth, 0)];
}
@end
